import tkinter as tk
import pandas as pd

from PIL import Image, ImageTk
import pyechers_view
import function_data

w_box = 20
h_box = 20




def resize(w, h, w_box, h_box, pil_image):
    """
    图标的尺寸自适应
    :param w:
    :param h:
    :param w_box:
    :param h_box:
    :param pil_image:
    :return:
    """
    f1 = 1.0 * w_box / w  # 1.0 forces float division in Python2
    f2 = 1.0 * h_box / h
    factor = min([f1, f2])
    width = int(w * factor)
    height = int(h * factor)
    return pil_image.resize((width, height), Image.ANTIALIAS)


root = tk.Tk()
# 设置标题
root.title('疫情小助手')

# 设置窗口大小
width = 711
height = 400
# 获取屏幕尺寸以计算布局参数，使窗口居屏幕中央
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height - 200) / 2)
root.geometry(alignstr)
# 设置窗口是否可变长、宽
root.resizable(width=False, height=False)

pil_image = Image.open("data/image/搜索.gif")
w, h = pil_image.size
pil_image_resized = resize(w, h, w_box, h_box, pil_image)
tk_image = ImageTk.PhotoImage(pil_image_resized)

# 增加背景图片

photo = tk.PhotoImage(file="data/image/back.gif", width=711)
theLabel = tk.Label(root, justify=tk.LEFT, image=photo, compound=tk.CENTER, font=("华文行楷", 20),
                    fg="white", text="")  # 前景色
contentEntry = tk.StringVar()

theLabel.pack()

mainmenu = tk.Menu(root)
menuFile = tk.Menu(mainmenu)  # 菜单分组 menuFile
mainmenu.add_cascade(label="世界疫情", menu=menuFile)
menuFile.add_command(label="世界疫情地图", command=pyechers_view.map_of_the_world)
menuFile.add_command(label="海外主要国家确诊/治愈率/死亡率趋势",command=pyechers_view.major_overseas_countries)
menuFile.add_separator()  # 分割线
menuFile.add_command(label="退出", command=root.destroy)

menuEdit = tk.Menu(mainmenu)  # 菜单分组 menuEdit
mainmenu.add_cascade(label="中国疫情", menu=menuEdit)
menuEdit.add_command(label="中国疫情严重省份词云", command=function_data.word_cloud)
menuEdit.add_command(label="中国疫情地图", command=pyechers_view.map_of_china_hot)
menuEdit.add_command(label="全国病例趋势图", command=pyechers_view.guangzhou_china)
menuEdit.add_command(label="全国疫情新增趋势", command=pyechers_view.the_new_trend)

root.config(menu=mainmenu)
# 进入消息循环
root.mainloop()
